<div id="divFirstHeader"></div>  <div class="header">
    <div class="title">
        <?php echo $this->element('print/title'); ?>
        <table>
            <tr>
                <td width="120px"><label>Vendor</label></td>
                <td colspan="3"><?php echo $this->data['CustStockInHead']['dispatch_from'] == ITS_PREFIX ? $this->requestAction('system_preferences/get/company_name') : $this->data['Supplier']['name']; ?></td>
            </tr>
        </table>
    </div>
    <div class="documentTitle">
        <div class="documentNote">STOCK IN NOTE</div>
        <table class="documentNo">
            <tr>
                <td><label>Stock in no.</label></td>
                <td><?php echo $this->data['CustStockInHead']['stock_in_no']; ?></td>
            </tr>
        </table>
        <table>
            <tr>
                <td><label>Stock in date</label></td>
                <td><?php echo $this->data['CustStockInHead']['stock_in_date']; ?></td>
                <td><label>Page</label></td>
                <td><span class="pageNo">1/1</span></td>
            </tr>
            <tr>
                <td width="120px"><label>Stock in by</label></td>
                <td colspan="3"><?php echo $this->data['CustStockInHead']['stock_in_by']; ?></td>
            </tr>
            <tr>
                <td><label>Ref. by Dispatch no.</label></td>
                <td colspan="3">
                    <?php if ($this->data['CustStockInHead']['dispatch_from'] == ITS_PREFIX) : ?>
                        <?php echo $this->data['Dispatch']['dispatch_no']; ?>
                    <?php else : ?>
                        <?php echo $this->data['SDH']['dispatch_no']; ?>
                    <?php endif; ?>
                </td>
            </tr>
        </table>
    </div>
    <table class="wide clear">
        <tr>
            <td width="120px"><label>Customer no.</label></td>
            <td width="271px"><?php echo $this->data['Customer']['cust_no']; ?></td>
            <td width="80px"><label>Site no.</label></td>
            <td><?php echo $this->data['Site']['site_no']; ?></td>
        </tr>
        <tr>
            <td><label>Customer name</label></td>
            <td><?php echo $this->data['Customer']['name']; ?></td>
            <td><label>Site name</label></td>
            <td><?php echo $this->data['Site']['name']; ?></td>
        </tr>
    </table>
</div>

<div class="main">
    <table id="dataTable" class="dataTable" cellspacing="0" cellpadding="0" >
        <thead id="tableHead">
            <tr align="center">
                <th width="40px">Item<br>ลำดับ</th>
                <th width="130px">Part Number<br>รหัสสินค้า</th>
                <th>Description<br />รายการ</th>
                <th width="45px">Qty<br />จำนวน</th>
                <th width="45px">Unit<br />หน่วย</th>
                <th width="90px">Location<br />ตำแหน่ง</th>
                <?php if ($see_current_stock) { ?>
                    <th width="85px">Current Stock<br />จำนวนคงเหลือ</th>
                <?php } ?>
            </tr>
        </thead>
        <tbody id="tableBody">
            <?php $i = 0;
            foreach ($this->data['CustStockIn'] as $is) : ?>
                <?php
                $pl_count = count($is['ProductLocation']);
                for ($j = 0; $j < $pl_count; ++$j):
                    ?>
                    <tr id="row<?php echo $i; ?>" class="row">
                        <td class="center rowTd"><?php echo $j == 0 ? ($i + 1) : '&nbsp;'; ?></td>
                        <td>
                            <?php echo $this->data['CustStockInHead']['dispatch_from'] == ITS_PREFIX ? $is['Product']['part_no'] : $is['Product']['supplier_part_no']; ?><br />
                            <?php echo $is['CustProductSite']['stock_code']; ?>
                        </td>
                        <td>
                            <?php
                            echo!empty($is['CustProductSite']['text']) ?
                                    $is['CustProductSite']['text'] :
                                    $is['Product']['text'];
                            ?>
                        </td>
                        <td class="text-right"><?php echo $is['ProductLocation'][$j]['stock_in_qty']; ?></td>
                        <td class="center"><?php echo $is['Product']['Unit']['title']; ?></td>
                        <td>
                            <?php
                            echo!empty($is['ProductLocation'][$j]['CustLocation']['name']) ?
                                    $is['ProductLocation'][$j]['CustLocation']['name'] :
                                    'N/A'; // แสดง Location ถ้ามีข้อมูลอยู่
                            ?>
                        </td>
                    <?php if ($see_current_stock) { ?>
                            <td class="text-right"><?php echo!empty($is['current_stock']) ? $is['current_stock'] : '-'; ?></td>
                    <?php } ?>
                    </tr>
                    <?php
                    // ถ้ามีแถวที่มี serial no หรือ other information อยู่ (ถ้าไม่มี จะมี แถวว่างมา 1 แถว)
                    $k = 0;
                    foreach ($is['ProductLocation'][$j]['PS'] as $ps) :
                        if (!empty($ps['ProductSerial']['serial_no']) || !empty($ps['ProductSerial']['other_information'])) :
                            ?>
                            <tr class="product_serials_row">
                                <td>&nbsp;</td>
                                <td class="rowTd">
                                    <span class="product_serial_no"><?php echo++$k; ?>&nbsp;</span>
                                    <span><?php echo!empty($ps['ProductSerial']['serial_no']) ? $ps['ProductSerial']['serial_no'] : 'N/A' ?></span>
                                </td>
                                <td>
                                    <span><?php echo!empty($ps['ProductSerial']['other_information']) ? $ps['ProductSerial']['other_information'] : 'N/A' ?></span>
                                </td>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                            <?php if ($see_current_stock) { ?>
                                    <td>&nbsp;</td>
                            <?php } ?>
                            </tr>
                        <?php endif;
                    endforeach; ?>
                    <?php endfor;
                    ++$i; ?>
                <?php endforeach; ?>
                <?php for ($i = 0; $i < 20; ++$i) : ?>
                <tr class="emptyRow"> <!-- สร้างแถวเปล่าขึ้นมาเพื่อยืดขนาดตารางให้เต็มหน้า-->
                    <td class="rowTd">&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>
    <?php if ($see_current_stock) { ?>
                        <td>&nbsp;</td>
    <?php } ?>
                </tr>
<?php endfor; ?>
        </tbody>
    </table>
</div>

<div class="footer">
    <div class="custSignature">
        <hr />
        <span>Customer Staff/Date</span>
    </div>
</div>
<div id="divLastFooter"><?php debug($see_current_stock); ?></div>